/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare",
        "scprit/followup/app/datatable/datatable.servers.js",
        "scprit/followup/app/datatable/datatable.ui.js"],
    function($,$bb,$datatableServers,$datatableUi){
        var servers = {};
        var URL = $bb.baseUrl("department")+"followup/service";
        /**
         * 入参
         */
        var inParams = function(args){
            var data = JSON.stringify({
                data: {
                    "args": JSON.stringify(args),
                    "phoneNo": $.trim($('#phone').val()),
                    "userName": $.trim($('#userName').val())
                }
            });
            return data;
        }
        /**
         * 出参
         */
        var outParams = function(data){
            return data.rows;
        };
        /**
         * columns
         */
        //授权状态：
        var status = function(e){
            return e.authStatus == "1" ? '<span class="status">已授权</span>' : "<span>未授权</span>";
        };
        var columnsData = function(){
            var columnsArr = ['userName','phoneNo',status];
            return $datatableServers.getColumnsData(columnsArr);
        };
        /*
        * 初始化后的回调函数：
        * */
        var initComplete = function(){
            $("#phone,#userName").on("input propertychange",function(){
                $datatableUi.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            });
        };
        /**
         * 获取datatable里的options
         */
        servers.getOptions = function(){
            var sessionId = $bb.getSessionStorage("sessionId");
            var options = {
                "ajax": {
                    "url": URL + "/nutrition/authorization/list?sessionId=" + sessionId,
                    "data": inParams,
                    "dataSrc": outParams
                },
                "columns": columnsData(),
                "initComplete": initComplete
            };
            return options;
        };
        return servers;
    });